﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using HumanManagement.BusinessObjects;

namespace HumanManagement.DataAccess
{
	public class ForeignLanguageDA
	{

		#region ***** Init Methods ***** 
		public ForeignLanguageDA()
		{
		}
		#endregion

		#region ***** Get Methods ***** 
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public ForeignLanguage Populate(IDataReader myReader)
		{
			ForeignLanguage obj = new ForeignLanguage();
			obj.ID = (int) myReader["ID"];
			obj.ForeignLanguage_Field = (string) myReader["ForeignLanguage"];
			obj.Used = (string) myReader["Used"];
			obj.Descripton = (string) myReader["Descripton"];
			return obj;
		}

		/// <summary>
		/// Get ForeignLanguage by id
		/// </summary>
		/// <param name="id">ID</param>
		/// <returns>ForeignLanguage</returns>
		public ForeignLanguage GetByID(int id)
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_ForeignLanguage_GetByID", Data.CreateParameter("ID", id)))
			{
				if (reader.Read())
				{
					return Populate(reader);
				}
				return null;
			}
		}

		/// <summary>
		/// Get all of ForeignLanguage
		/// </summary>
		/// <returns>List<<ForeignLanguage>></returns>
		public List<ForeignLanguage> GetList()
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_ForeignLanguage_Get"))
			{
				List<ForeignLanguage> list = new List<ForeignLanguage>();
				while (reader.Read())
				{
				list.Add(Populate(reader));
				}
				return list;
			}
		}

		/// <summary>
		/// Get DataSet of ForeignLanguage
		/// </summary>
		/// <returns>DataSet</returns>
		public DataSet GetDataSet()
		{
			return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ForeignLanguage_Get");
		}


		/// <summary>
		/// Get all of ForeignLanguage paged
		/// </summary>
		/// <param name="recperpage">record per page</param>
		/// <param name="pageindex">page index</param>
		/// <returns>List<<ForeignLanguage>></returns>
		public List<ForeignLanguage> GetListPaged(int recperpage, int pageindex)
		{
			using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_ForeignLanguage_GetPaged"
							,Data.CreateParameter("recperpage", recperpage)
							,Data.CreateParameter("pageindex", pageindex)))
			{
				List<ForeignLanguage> list = new List<ForeignLanguage>();
				while (reader.Read())
				{
				list.Add(Populate(reader));
				}
				return list;
			}
		}

		/// <summary>
		/// Get DataSet of ForeignLanguage paged
		/// </summary>
		/// <param name="recperpage">record per page</param>
		/// <param name="pageindex">page index</param>
		/// <returns>DataSet</returns>
		public DataSet GetDataSetPaged(int recperpage, int pageindex)
		{
			return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ForeignLanguage_GetPaged"
							,Data.CreateParameter("recperpage", recperpage)
							,Data.CreateParameter("pageindex", pageindex));
		}





		#endregion

		#region ***** Add Update Delete Methods ***** 
		/// <summary>
		/// Add a new ForeignLanguage within ForeignLanguage database table
		/// </summary>
		/// <param name="obj">ForeignLanguage</param>
		/// <returns>key of table</returns>
		public int Add(ForeignLanguage obj)
		{
			DbParameter parameterItemID = Data.CreateParameter("ID", obj.ID);
			parameterItemID.Direction = ParameterDirection.Output;
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ForeignLanguage_Add"
							,parameterItemID
							,Data.CreateParameter("ForeignLanguage", obj.ForeignLanguage_Field)
							,Data.CreateParameter("Used", obj.Used)
							,Data.CreateParameter("Descripton", obj.Descripton)
			);
			return (int)parameterItemID.Value;
		}

		/// <summary>
		/// updates the specified ForeignLanguage
		/// </summary>
		/// <param name="obj">ForeignLanguage</param>
		/// <returns></returns>
		public void Update(ForeignLanguage obj)
		{
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ForeignLanguage_Update"
							,Data.CreateParameter("ID", obj.ID)
							,Data.CreateParameter("ForeignLanguage", obj.ForeignLanguage_Field)
							,Data.CreateParameter("Used", obj.Used)
							,Data.CreateParameter("Descripton", obj.Descripton)
			);
		}

		/// <summary>
		/// Delete the specified ForeignLanguage
		/// </summary>
		/// <param name="id">ID</param>
		/// <returns></returns>
		public void Delete(int id)
		{
			SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure,"sproc_ForeignLanguage_Delete", Data.CreateParameter("ID", id));
		}
		#endregion
	}
}
